// 导航栏主题切换
function navqiehuan() {
    var nav = $("#nav");
    // nav[0].className = "nav navbar-inverse" > 5 ? "":"";
    // if (nav[0].tagName.toLowerCase() == 'nav') {
    //     var className = nav[0].className = 'nav navbar-default'  ?  'nav navbar-inverse':'nav navbar-default';
    //     nav[0].className = className;
    // }
}

/* 上传图片 */
function uploadFile() {
    var form = new FormData(document.getElementById("specialForm"));
    $.ajax({
        url: 'http://127.0.0.1:8085/uploadfile/image',
        type: 'POST',
        data: form,
        processData: false,// 不处理数据
        contentType: false, // 不设置内容类型
        success:function (result) {
            if (result.surl != "") {
                layer.msg('上传成功！',{icon:1,time:1200});
                $("#surl").val(result.surl); //将图片路径填充到前台
            }
        },
        error: function () {
            layer.msg('API接口异常!',{icon:0,time:1200});
        }
    })
}

/**
 * 个人分类管理事件
 * */
// 异步新建个人分类
function createSpecial() {
    if (/\S/.test($("#sname").val()) && /\S/.test($("#sdescribe").val())) {
        var special = $("#specialForm").serialize();
        $.ajax({
            type: "post",
            url: "/special/saveSpecial",
            async: true,
            data: special,
            success: function (resultMsg) {
                if (resultMsg.state == 201) {
                    layer.msg(resultMsg.msg,{icon:6,time:1500,end:function () {
                            $("#specialForm")[0].reset();
                            window.location.reload(); //刷新当前页面
                        }});
                }else {
                    layer.msg(resultMsg.msg,{icon:5,time:1500});
                }
            },
            error: function () {
                layer.msg('API接口异常，稍后重试。',{icon:2,time: 1500});
            }
        });
    }else {
        layer.msg('不能为空!',{icon:0,time:1500});
    }
}
// 通过id逻辑删除及恢复个人分类
function delSpecial(sid,dedid) {
    // console.log("逻辑删除查询条件"+dedid);
    var did = dedid == 1 ? '确定将此分类放入回收站吗？' : '确定恢复此分类吗？';
    layer.confirm(did,{
       btn:['确认','取消']
    },function () {
        layer.msg('正在操作,请稍等！',{icon:16,shade:0.01});
        $.ajax({
            type: "get",
            url: "/special/del-special",
            async: true,
            data: {"sid":sid,"dedid":dedid},
            success: function (resultMsg) {
                if (resultMsg.state == 200 && dedid == 1) {
                    layer.msg(resultMsg.msg, {
                        icon: 1, time: 1500, end: function () {
                            window.location.reload();//刷新
                        }
                    });

                } else if (resultMsg.state == 200 && dedid == 0) {
                    layer.msg(resultMsg.msg, {
                        icon: 1, time: 1500, end: function () {
                            recycleSpecial();//刷新到回收站
                        }
                    });
                }else {
                    layer.msg(resultMsg.msg,{icon:2,time:1500});
                }
            },
            error: function () {
                layer.msg('API接口异常!',{icon:0,time: 1500});
            }
        });
    },function () {
        layer.msg('已取消操作!',{icon:0,time:1000});
    });
}
// 个人分类回收站查询点击事件
function recycleSpecial(page,size) {
    // console.log(page+size)
    var $topz = $("#topz"); // 按钮组
    var $recycleSpecial = $("#recycleSpecial"); //分类展示区域
    var $fenlei = $("#fenlei");
    var $fenye = $("#fenye");
    var topz = "";
    var recycle = "";
    layer.msg('正在操作，请稍后！',{icon:16,shade: 0.01,time:800});
    $.ajax({
        type: "get",
        url: "/special/recycle-special",
        async: true,
        data:{"page":page,"size":size},
        success: function (pageSpecial) {
            topz = '<!--     分类管理区域   -->\n' +
                '                   <ul class="nav nav-tabs">\n' +
                '                       <li class="specialfy ">\n' +
                '                           <a onclick="window.location.reload();">全部</a>\n' +
                '                       </li>\n' +
                '                       <li class="specialfy active">\n' +
                '                           <a  onclick="recycleSpecial(2)">回收站('+pageSpecial.total+')</a>\n' +
                '                       </li>\n' +
                '                   </ul>';
            if (pageSpecial.total <= 0) {
                recycle = '<div style="margin-top: 25px;border: 1px dashed #7f8087;width: available;"></div>\n' +
                    '          <div style="text-align: center;margin-top: 25px;">暂无回收分类</div>\n' +
                    '      <div style="margin-top: 24px;border: 1px dashed #7f8087;width: available;"></div>';
                $recycleSpecial.html(recycle);
            }else {
                var fenlei = "";
                // 遍历回收分类信息
                $(pageSpecial.objects).each(function (index,item) {
                    fenlei += '<div style="float: left;margin: 20px 0 0 43px;">\n' +
                        '              <img src="'+item.surl+'" class="img-rounded" width="50px" height="50px">\n' +
                        '                   &emsp;&emsp;\n' +
                        '                   <span style="font-size: 18px;font-weight: 600;" >'+item.sname+'</span>\n' +
                        '         </div>\n' +
                        '         <div style="margin:35px 0 0 700px;">\n' +
                        '              <div class="btn-group-sm">\n' +
                        '                   <button type="button" class="btn btn-link" style="text-decoration: none;outline: none;" onclick="delSpecial('+item.sid+','+0+')">恢复</button>\n' +
                        '                   &boxv;\n' +
                        '                   <button type="button" class="btn btn-link" style="text-decoration: none;outline: none;" onclick="deleteSpecial('+item.sid+')" >永久删除</button>\n' +
                        '              </div>\n' +
                        '         </div>'+
                        '       <div style="margin-top: 24px;border: 1px dashed #7f8087;width: available;"></div>';
                });
                $fenlei.html(fenlei);
            //    分页
                var fenye = "";
                fenye += '<ul class="pagination">\n' +
                    '            <li ><a onclick="recycleSpecial('+pageSpecial.current+'-1 <= 0 ? 1 : '+pageSpecial.current+' ,'+pageSpecial.size+')">&laquo;</a></li>\n';
                for (let i = 1; i <= pageSpecial.pages; i++) {
                    fenye += '<!--   中间页 -->\n' +
                            ' <li><a onclick="recycleSpecial('+i+','+pageSpecial.size+')"" >'+i+'</a></li>\n';
                }
                fenye += ' <li ><a  onclick="recycleSpecial('+pageSpecial.current+'+1 ,'+pageSpecial.size+')"" >&raquo;</a></li>\n' +
                         ' </ul>';
                $fenye.html(fenye);
            }
            $topz.html(topz);
        },
        error: function () {
            layer.msg('API接口异常!',{icon:0,time: 1500});
        }
    });
}
// 永久删除分类
function deleteSpecial(sid) {
    layer.confirm('确定要永久删除吗？',{
        btn: ['确定','取消']
    },function () {
        layer.msg('正在操作，请稍后！',{icon:16,shade: 0.01,time:1200});
        $.get('/special/delete-special',
            {"sid":sid},
            function (resultMsg) {
                if (resultMsg.state == 200) {
                    layer.msg(resultMsg.msg,{icon:6,time:1500,end:function () {
                            recycleSpecial(1,5);//刷新到回收站
                        }});
                } else {
                    layer.msg(resultMsg.msg,{icon:5,time:1500});
                }
            });
    },function () {
        layer.msg('已取消操作!',{icon:0,time:1500});
    });
}
// 查询单独分类
function modelUpdate(sid,dedid) {
    var $createSpecial = $("#createSpecial");
    var createSpecial = "";
    $.post('/special/select-bysid',
        {"sid":sid,"dedid":dedid},
        function (special) {
        createSpecial += '<div class="modal-dialog">\n' +
            '        <div class="modal-content">\n' +
            '            <div class="modal-header">\n' +
            '                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">\n' +
            '                    &times;\n' +
            '                </button>\n' +
            '                <h4 class="modal-title" style="font-weight: 600" id="myModalLabel">\n' +
            '                    个人分类\n' +
            '                </h4>\n' +
            '            </div>\n' +
            '            <div class="modal-body">\n' +
            '                <form class="form-horizontal row" role="form" id="specialForm">\n' +
            '                    <div class="form-group">\n' +
            '                        <label class="col-sm-2 control-label" for="sname">分类名称：</label>\n' +
            '                        <div class="col-sm-10">\n' +
            '                            <input type="text" class="form-control" name="sname" id="sname" placeholder="请输入分类名称" value="'+special.sname+'" />\n' +
            '                        </div>\n' +
            '                    </div>\n' +
            '                    <div class="form-group">\n' +
            '                        <label class="col-sm-2 control-label" for="sdescribe">描述：</label>\n' +
            '                        <div class="col-sm-10">\n' +
            '                            <textarea name="sdescribe" id="sdescribe" maxlength="255" class="form-control" placeholder="请描述一下该分类">'+special.sdescribe+'</textarea>\n' +
            '                        </div>\n' +
            '                    </div>\n' +
            '                    <div class="form-group">\n' +
            '                        <label class="col-sm-2 control-label" for="surl">图片：</label>\n' +
            '                        <div class="col-sm-10">\n' +
            '                            <input type="file"  name="surl" id="surl" />\n' +
            '                        </div>\n' +
            '                    </div> '+
            '                  <input type="hidden" name="sid" id="sid" value="'+special.sid+'">         '+
            '                </form>\n' +
            '            </div>\n' +
            '            <div class="modal-footer">\n' +
            '                <button type="button" class="btn btn-default" data-dismiss="modal" >关闭\n' +
            '                </button>\n' +
            '                <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="updateSpecial()" >\n' +
            '                    提交\n' +
            '                </button>\n' +
            '            </div>\n' +
            '        </div><!-- /.modal-content -->\n' +
            '    </div><!-- /.modal -->';
        $createSpecial.html(createSpecial);
    })

}
// 编辑单独分类
function updateSpecial() {
    var specialForm = $("#specialForm").serialize();
    $.post("/special/updateSpecial",
        specialForm,
        function (resultMsg) {
            if (resultMsg.state == 201) {
                layer.msg(resultMsg.msg,{icon:6,time:1500,end:function () {
                        window.location.reload(); //刷新当前页面
                    }});
            }else {
                layer.msg(resultMsg.msg,{icon:5,time:1500});
            }
        });
}

/**
 * 个人文章管理事件
 */
// 通过id逻辑删除及恢复个人文章
function delEssay(eid,dedid,status) {
    // console.log(eid+"\t"+dedid);
    var did = dedid == 1 ? '确定将此文章放入回收站吗？' : '确定恢复此文章吗？';
    layer.confirm(did,{
        btn:['确认','取消']
    },function () {
        layer.msg('正在操作,请稍等！',{icon:16,shade:0.01});
        $.ajax({
            type: "get",
            url: "/essay/del-essay",
            async: true,
            data: {"eid":eid,"dedid":dedid},
            success: function (resultMsg) {
                if (resultMsg.state == 200 && dedid == 1 && status == -1) {
                    layer.msg(resultMsg.msg, {
                        icon: 1, time: 1500, end: function () {
                            window.location.reload();//刷新
                        }
                    });
                }  else if (resultMsg.state == 200 && dedid == 1 && status == 0 || status == 1) {
                    layer.msg(resultMsg.msg, {
                        icon: 1, time: 1500, end: function () {
                            openEssay(1,5,status);//刷新到当前
                        }
                    });
                }  else if (resultMsg.state == 200 && dedid == 0) {
                    layer.msg(resultMsg.msg, {
                        icon: 1, time: 1500, end: function () {
                            recycleEssay(1,5);//刷新到回收站
                        }
                    });
                }else {
                    layer.msg(resultMsg.msg,{icon:2,time:1500});
                    recycleEssay(1,5);//刷新到回收站
                }
            },
            error: function () {
                layer.msg('API接口异常!',{icon:0,time: 1500});
            }
        });
    },function () {
        layer.msg('已取消操作!',{icon:0,time:1000});
    });


}
// 个人文章回收站查询点击事件
function recycleEssay(page,size) {
    // console.log(page+"\t"+size);
    var $topz = $("#topz"); // 按钮组
    var $recycleEssay = $("#recycleEssay"); //文章展示区域
    var $wenzhang = $("#wenzhang"); //文章区域
    var $fenye = $("#fenye"); //分页
    var topz = "";
    var recycle = "";
    var essay = "";
    var fenye = "";
    layer.msg('正在操作，请稍后！',{icon:16,shade: 0.01,time:800});
    $.ajax({
        type: "get",
        url: "/essay/recycle-essay",
        async: false,
        data: {"page":page,"size":size},
        success:function (pageEssay) {
            topz += '<ul class="nav nav-tabs">\n' +
                '               <li class="">\n' +
                '                   <a onclick="window.location.reload();">全部</a>\n' +
                '               </li>\n' +
                '               <li class="">\n' +
                '                   <a onclick="openEssay('+page+','+size+',0)">公开</a>\n' +
                '               </li>\n' +
                '               <li class="">\n' +
                '                   <a onclick="openEssay('+page+','+size+',1)">私有</a>\n' +
                '               </li>\n' +
                '               <li class="active">\n' +
                '                   <a onclick="recycleEssay('+page+','+size+')">回收站('+pageEssay.total+')</a>\n' +
                '               </li>\n' +
                '            </ul>';
            if (pageEssay.total <= 0) {
                recycle += '<div style="margin-top: 15px;">\n' +
                    '                <div style="margin-top: 30px;border: 1px dashed #7f8087;width: available;"></div>\n' +
                    '                <span id="wenzhang">\n' +
                    '                    <div style="text-align: center;margin-top: 25px;">暂无文章</div>\n' +
                    '                    <div style="margin-top: 30px;border: 1px dashed #7f8087;width: available;"></div>\n' +
                    '                </span>\n' +
                    '                <!--            分页          -->\n' +
                    '                <div class="plq" id="fenye" style="text-align: center;"></div>\n' +
                    '            </div>';
                $recycleEssay.html(recycle);
            } else {
            //    遍历文章信息加载到页面
                $(pageEssay.objects).each(function (index,item) {
                    //标准日期转换
                    var gmtCreate = dateTime(new Date(item.gmtCreate));
                    essay += '<h4 style="margin-top: 19px;font-weight: 600;">\n' +
                    '                       <a  style="color: #0d1021" >'+item.etitle+'</a>\n' +
                    '                    </h4>\n' +
                    '                    <span >';
                    if (item.estate == 0) {
                        essay += '<span>原创</span>\n';
                    } else {
                        essay += '<span>转载</span>\n';
                    }
                    essay += ' &emsp;\n' +
                    '                        <span >'+gmtCreate+'</span>&emsp;&emsp;\n' +
                    '                        <img src="/images/index/fw.png" class="img-circle" width="20px" height="20px" alt="访问量" title="访问量">\n' +
                    '                            <span >'+item.eReadStatis+'</span>\n' +
                    '                            &emsp;\n' +
                    '                        <img src="/images/index/comment.png" class="img-circle" width="20px" height="20px"  alt="评论量" title="评论量">\n' +
                    '                            <span >0</span>\n' +
                    '                            &emsp;\n' +
                    '                        <img src="/images/index/dz0.png" class="img-circle" style="margin-top: -5px;" width="20px" height="20px"  alt="收藏量" title="收藏量">\n' +
                    '                            <span >0</span>\n' +
                    '                            &emsp;\n' +
                    '                        <img src="/images/index/shoucang.png" class="img-circle" width="20px" height="20px"  alt="收藏量" title="收藏量">\n' +
                    '                            <span >0</span>\n' +
                    '                        <div style="float: right">\n' +
                    '                            <div class="btn-group-sm">\n' +
                    '                                 <button type="button" class="btn btn-link" style="text-decoration: none;outline: none;" onclick="delEssay('+item.eid+',0)">恢复</button>\n' +
                    '                                    &boxv;\n' +
                    '                                <button type="button" class="btn btn-link" style="text-decoration: none;outline: none;" onclick="deleteEssay('+item.eid+')">永久删除</button>\n' +
                    '                            </div>\n' +
                    '                        </div>'+
                    '                    </span>'+
                    '               <div style="margin-top: 30px;border: 1px dashed #7f8087;width: available;"></div>';
                });
            //    遍历分页信息
                fenye += '<ul class="pagination">\n' +
                    '                    <li ><a onclick="recycleEssay('+pageEssay.current+'-1 <=0 ? 1 : '+pageEssay.current+'-1 ,'+pageEssay.size+')" >&laquo;</a></li>\n';
                for (let i = 1; i <= pageEssay.pages; i++) {
                    fenye += '<li class="" >\n' +
                        '        <a onclick="recycleEssay('+i+','+pageEssay.size+')">'+i+'</a>\n' +
                        '     </li>\n';
                };
                fenye += '<li ><a onclick="recycleEssay('+pageEssay.current+'+1,'+pageEssay.size+')" >&raquo;</a></li>' +
                        ' </ul>';
            }
            $topz.html(topz);
            $wenzhang.html(essay);
            $fenye.html(fenye);
        },
        error: function () {
            layer.msg('API接口异常!',{icon:0,time: 1500});
        }
    });
}
// 永久删除文章
function deleteEssay(eid) {
    console.log(eid)
    layer.confirm('确定要永久删除吗？',{
        btn: ['确定','取消']
    },function () {
        layer.msg('正在操作，请稍后！',{icon:16,shade: 0.01});
        $.get('/essay/delete-essay',
            {"eid":eid},
            function (resultMsg) {
                if (resultMsg.state == 200) {
                    layer.msg(resultMsg.msg,{icon:6,time:1500,end:function () {
                            recycleEssay(1,5);//刷新到回收站
                        }});
                } else {
                    layer.msg(resultMsg.msg,{icon:5,time:1500});
                }
            });
    },function () {
        layer.msg('已取消操作!',{icon:0,time:1500});
    });
}
//设置公开/私有文章
function updateOpenOrPrivate(eid,estatus,status1) {
    console.log(eid,estatus,status1);
    var status = estatus == 0 ? 1:0;
    layer.msg('正在处理请稍后。。。',{icon:16,shade:0.01});
    $.post('/essay/update-open-or-private',
        {"eid":eid,"estatus":estatus},
        function (result) {
            if (status1 == -1) {
                window.location.reload(); //页面整体刷新
            }else {
                openEssay(1,5,status);//刷新到当前页
            }
    });
}
// 公开/私有文章查询
function openEssay(page,size,status) {
    var $topz = $("#topz"); // 按钮组
    var $recycleEssay = $("#recycleEssay"); //文章展示区域
    var $wenzhang = $("#wenzhang"); //文章区域
    var $fenye = $("#fenye"); //分页
    var topz = "";
    var recycle = "";
    var essay = "";
    var fenye = "";
    layer.msg('正在操作，请稍后！',{icon:16,shade: 0.01,time:800});
    $.ajax({
        type: "get",
        url: "/essay/open-essay",
        async: false,
        data: {"page":page,"size":size,"status":status},
        success:function (pageEssay) {
            // 判断点击是否公有/私有
            if (status == 0) {
                topz += '<ul class="nav nav-tabs">\n' +
                    '               <li class="">\n' +
                    '                   <a onclick="window.location.reload();">全部</a>\n' +
                    '               </li>\n' +
                    '               <li class="active">\n' +
                    '                   <a onclick="openEssay('+page+','+size+',0)">公开('+pageEssay.total+')</a>\n' +
                    '               </li>\n' +
                    '               <li class="">\n' +
                    '                   <a onclick="openEssay('+page+','+size+',1)">私有</a>\n' +
                    '               </li>\n' +
                    '               <li class="">\n' +
                    '                   <a onclick="recycleEssay('+page+','+size+')">回收站</a>\n' +
                    '               </li>\n' +
                    '            </ul>';
            } else if (status == 1) {
                topz += '<ul class="nav nav-tabs">\n' +
                    '               <li class="">\n' +
                    '                   <a onclick="window.location.reload();">全部</a>\n' +
                    '               </li>\n' +
                    '               <li class="">\n' +
                    '                   <a onclick="openEssay('+page+','+size+',0)">公开</a>\n' +
                    '               </li>\n' +
                    '               <li class="active">\n' +
                    '                   <a onclick="openEssay('+page+','+size+',1)">私有('+pageEssay.total+')</a>\n' +
                    '               </li>\n' +
                    '               <li class="">\n' +
                    '                   <a onclick="recycleEssay('+page+','+size+')">回收站</a>\n' +
                    '               </li>\n' +
                    '            </ul>';
            }
            if (pageEssay.total <= 0 && status == 0) {
                recycle += '<div style="margin-top: 15px;">\n' +
                    '                <div style="margin-top: 30px;border: 1px dashed #7f8087;width: available;"></div>\n' +
                    '                <span id="wenzhang">\n' +
                    '                    <div style="text-align: center;margin-top: 25px;">暂无公有文章</div>\n' +
                    '                    <div style="margin-top: 30px;border: 1px dashed #7f8087;width: available;"></div>\n' +
                    '                </span>\n' +
                    '                <!--            分页          -->\n' +
                    '                <div class="plq" id="fenye" style="text-align: center;"></div>\n' +
                    '            </div>';
                $recycleEssay.html(recycle);
            } else if (pageEssay.total <= 0 && status == 1) {
                recycle += '<div style="margin-top: 15px;">\n' +
                    '                <div style="margin-top: 30px;border: 1px dashed #7f8087;width: available;"></div>\n' +
                    '                <span id="wenzhang">\n' +
                    '                    <div style="text-align: center;margin-top: 25px;">暂无私有文章</div>\n' +
                    '                    <div style="margin-top: 30px;border: 1px dashed #7f8087;width: available;"></div>\n' +
                    '                </span>\n' +
                    '                <!--            分页          -->\n' +
                    '                <div class="plq" id="fenye" style="text-align: center;"></div>\n' +
                    '            </div>';
                $recycleEssay.html(recycle);
            }else {
                //    遍历文章信息加载到页面
                $(pageEssay.objects).each(function (index,item) {
                    //标准日期转换
                    var gmtCreate = dateTime(new Date(item.gmtCreate));
                    essay += '<h4 style="margin-top: 19px;font-weight: 600;">\n' +
                        '                       <a  style="color: #0d1021" >'+item.etitle+'</a>\n' +
                        '                    </h4>\n' +
                        '                    <span >';
                    if (item.estate == 0) {
                        essay += '<span>原创</span>\n';
                    } else {
                        essay += '<span>转载</span>\n';
                    }
                    essay += ' &emsp;\n' +
                        '                        <span >'+gmtCreate+'</span>&emsp;&emsp;\n' +
                        '                        <img src="/images/index/fw.png" class="img-circle" width="20px" height="20px" alt="访问量" title="访问量">\n' +
                        '                            <span >'+item.eReadStatis+'</span>\n' +
                        '                            &emsp;\n' +
                        '                        <img src="/images/index/comment.png" class="img-circle" width="20px" height="20px"  alt="评论量" title="评论量">\n' +
                        '                            <span >0</span>\n' +
                        '                            &emsp;\n' +
                        '                        <img src="/images/index/dz0.png" class="img-circle" style="margin-top: -5px;" width="20px" height="20px"  alt="点赞量" title="点赞量">\n' +
                        '                            <span >0</span>\n' +
                        '                            &emsp;\n' +
                        '                        <img src="/images/index/shoucang.png" class="img-circle" width="20px" height="20px"  alt="收藏量" title="收藏量">\n' +
                        '                            <span >0</span>\n' +
                        '                        <div style="float: right">\n' +
                        '                            <div class="btn-group-sm">\n' +
                        '                                 <button type="button" class="btn btn-link" style="text-decoration: none;outline: none;">查看</button>\n' +
                        '                                    &boxv;\n' +
                        '                                 <button type="button" class="btn btn-link" style="text-decoration: none;outline: none;">\n' +
                        '                                     <ul class="nav nav-tabs">\n' +
                        '                                         <li class="dropdown">';
                    if (item.estatus == 0) {
                        essay +=  '  <a class="dropdown-toggle btn btn-link"\n' +
                            '            style="text-decoration: none;border: 0px;outline: none;background: white;"\n' +
                            '        data-toggle="dropdown" href="#" >公开</a>'+
                            '       <ul class="dropdown-menu">' +
                            '           <li>' +
                            '               <a onclick="updateOpenOrPrivate('+item.eid+',1)" >私有</a>' +
                            '           </li>' +
                            '       </ul>' +
                            '   </li>' +
                            '</ul>' +
                            '</button>';
                    } else {
                        essay +=  '  <a class="dropdown-toggle btn btn-link"\n' +
                            '            style="text-decoration: none;border: 0px;outline: none;background: white;"\n' +
                            '        data-toggle="dropdown" href="#" >私有</a>' +
                            '       <ul class="dropdown-menu">' +
                            '           <li>' +
                            '               <a onclick="updateOpenOrPrivate('+item.eid+',0)">公开</a>' +
                            '           </li>' +
                            '       </ul>' +
                            '   </li>' +
                            '</ul>' +
                            '</button>';
                    }
                    essay += '                                    &boxv;\n' +
                        '                                <button type="button" class="btn btn-link" style="text-decoration: none;outline: none;">置顶</button>\n' +
                        '                                    &boxv;\n' +
                        '                                <button type="button" class="btn btn-link" style="text-decoration: none;outline: none;" onclick="delEssay('+item.eid+',1,'+status+')">删除</button>\n' +
                        '                            </div>'+
                        '                        </div>'+
                        '                    </span>'+
                        '               <div style="margin-top: 30px;border: 1px dashed #7f8087;width: available;"></div>';
                });
                //    遍历分页信息
                fenye += '<ul class="pagination">\n' +
                    '                    <li ><a onclick="openEssay('+pageEssay.current+'-1 <=0 ? 1 : '+pageEssay.current+'-1 ,'+pageEssay.size+','+status+')" >&laquo;</a></li>\n';
                for (let i = 1; i <= pageEssay.pages; i++) {
                    fenye += '<li class="" >\n' +
                        '        <a onclick="openEssay('+i+','+pageEssay.size+','+status+')">'+i+'</a>\n' +
                        '     </li>\n';
                };
                fenye += '<li ><a onclick="openEssay('+pageEssay.current+'+1,'+pageEssay.size+','+status+')" >&raquo;</a></li>' +
                    ' </ul>';
            }
            $topz.html(topz);
            $wenzhang.html(essay);
            $fenye.html(fenye);

        },
        error: function () {
            layer.msg('API接口异常!',{icon:0,time: 1500});
        }

    });
}
// 标准时间转化方法
function dateTime(date) {
    var y = date.getFullYear(); // 年
    var M = date.getMonth() + 1; // 月
    M = M < 10 ? '0' + M : M;
    var d = date.getDate(); // 日
    d = d < 10 ? ('0' + d) : d;
    var h = date.getHours(); // 获取时间
    var m = date.getMinutes() // 获取 分钟
    var s = date.getSeconds() // 获取秒
    return y + '-' + M + '-' + d+" "+h+":"+m+":"+s;
};

/**
 * 评论发表及管理
 */
// 检查用户是否登录
function inspect() {
    var $aid = $("#aid").val();
    if (/^\s*$/g.test($aid) || $aid == "") {
        layer.alert('请登录!',{icon:0})
    }else {
        $("#puslish").show();//显示出发表评论按钮
    }
}
// 提交评论
function publish() {
    const cname = $("#cname").val();
    const eid = $("#eid").val();
    var $aid = $("#aid").val();
    if (cname == "" || /\s/.test(eid)) {
        layer.msg('请填写评论内容',{icon:0,time: 1500});
    }else {
        $.ajax({
            type: "post",
            url: "/comment/publish",
            async: true,
            contentType: 'application/json;charset=utf-8',
            dataType: "json",
            data:JSON.stringify({"cmcomment":cname,"eid":eid,"aid":$aid}),
            success: function (resultMsg) {
                if (resultMsg.state == 201) {
                    layer.msg(resultMsg.msg,{icon:1,time:1500,end:function () {
                            selectByEid(eid,1,5);
                            $("#cname").val("");
                        }});
                } else {
                    layer.msg(resultMsg.msg,{icon:2,time:1500});
                }
            },
            error: function () {
                layer.msg('API数据接口异常',{icon:0,time:1500});
            }
        });
    }
}
// 异步获取所有关于此博客的评论
function selectByEid(eid,page,size) {
    var $plq = $("#plq"); //评论区控制权
    var $plfy = $("#plfy"); //评论区控制权
    var plq = "";
    var plfy = "";
    $.post('/comment/select-byeid',
        {"eid":eid,"page":page,"size":size},
        function (pageResult) {
            if (pageResult.total <= 0) {
                plq += '<div class="plq">\n' +
                    '      <div class="plguode">\n' +
                    '         <span>暂无评论,快来占领吧。</span>\n' +
                    '      </div>\n' +
                    '      <span class="hx4"></span>\n' +
                    '   </div>';
            }else {
                $(pageResult.objects).each(function (index,item) {
                    var gmtModified = dateTime(new Date(item.gmtModified));//发表时间
                    plq += '<div class="plq">\n' +
                        '         <div style="float: left;">\n' +
                        '              <a href="/#">\n' +
                        '                  <img src="/images/index/1.png" alt="头像" class="img-circle" width="30px" height="30px" style="float: left;margin: 4px 0 15px 0;">\n' +
                        '               </a>\n' +
                        '         </div>\n' +
                        '\n' +
                        '         <div class="plguode">\n' +
                        '               <a><span>&emsp;&emsp;'+item.userInfo.uname+':&nbsp;</span></a>\n' +
                        '               <span>'+item.cmcomment+'</span>\n' +
                        '               <div>\n' +
                        '                    <span style="float: right;">\n' +
                        '                    <span>'+gmtModified+'</span>\n' +
                        '                    &emsp;\n' +
                        '                    <img src="/images/index/dz0.png" width="25px">\n' +
                        '                    </span>\n' +
                        '               </div>\n' +
                        '          </div>\n' +
                        '          <span class="hx4"></span>\n' +
                        '   </div>';

                })

                plfy += '<ul class="pagination">\n' +
                    '  <li ><a onclick="selectByEid('+eid+','+pageResult.current+'-1 <=0 ? 1 : '+pageResult.current+'-1 ,'+pageResult.size+','+status+')" >&laquo;</a></li>\n';
                // 分页
                for (let i = 1; i <= pageResult.pages; i++) {
                    plfy += '<li class="" >\n' +
                        '        <a onclick="selectByEid('+eid+','+i+','+pageResult.size+')">'+i+'</a>\n' +
                        '     </li>\n';
                };
                plfy += '<li ><a onclick="selectByEid('+eid+','+pageResult.current+'+1,'+pageResult.size+')" >&raquo;</a></li>' +
                    ' </ul>';
            }
            $plq.html(plq);
            $plfy.html(plfy);
        })


}


